﻿//===================================================================================
// Copyright (c) Ryan Garrett.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===================================================================================

using System;
using System.Collections.Generic;

namespace Caffeine.Core.Test.TestModel
{
    public class ModelForRegisteringComputedProperties<T> : ModelBase
    {
        private readonly ModelProperty<T> _property;
        private readonly ModelProperty<T> _alternateProperty1;
        private readonly ModelProperty<T> _alternateProperty2;

        public ModelForRegisteringComputedProperties
        (
            Nullable<ModelPropertyBehaviors> behavior, 
            Func<IEnumerable<ModelProperty<T>>, T, T> computation, 
            Boolean registerComputedProperty
        )
        {
            _alternateProperty1 = RegisterProperty<T>("AlternateProperty1");
            _alternateProperty2 = RegisterProperty<T>("AlternateProperty2");

            if (registerComputedProperty)
            {
                _property = RegisterComputedProperty<T>("Property", computation, AlternateProperty1, AlternateProperty2);
            }
            else
            {
                _property = RegisterProperty<T>("Property", behavior);
            }
        }

        public ModelForRegisteringComputedProperties(Nullable<ModelPropertyBehaviors> behavior)
            : this(behavior, null, false)
        {
        }

        public ModelProperty<T> Property
        {
            get
            {
                return _property;
            }
        }

        public ModelProperty<T> AlternateProperty1
        {
            get
            {
                return _alternateProperty1;
            }
        }

        public ModelProperty<T> AlternateProperty2
        {
            get
            {
                return _alternateProperty2;
            }
        }
    }
}
